package com.sumainfor.pc.dev.controller;

import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.dev.dao.MessageMapper;
import com.sumainfor.pc.dev.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 通知管理列表
 * <p>
 *
 * @author: zhoucong
 * @create: 2019-05-07 18:38
 **/
@Controller
@RequestMapping("/message")
public class MessageController {
    @Autowired
    MessageService messageService;

    @Autowired
    MessageMapper messageMapper;

    /**
    * <p>
    * 查看通知管理
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @ResponseBody
    @GetMapping("/getMessage")
    public JsonResult getMessage(@RequestParam Map<String,Object> params, Pager pager){
        pager.setPagerNecessary(params,pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout = messageMapper.getMessageCount(params);
        System.out.println("cout"+cout);
        if(cout == 0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(),params,cout);
        }else {
            List<Map<String, Object>> getMessage = messageService.getMessage(params);
            return pageUtils.getJsonResult(getMessage,params,cout);
        }
    }

    /**
    * <p>
    * 编辑通知管理
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @ResponseBody
    @PostMapping("/updateMessage")
    public JsonResult updateMessage(@RequestBody Map<String,Object> params){
        return messageService.updateMessage(params);
    }

    /**
    * <p>
    * 删除通知管理
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @ResponseBody
    @PostMapping("/deleteMessage")
    public JsonResult deleteMessage(@RequestBody Map<String,Object> params){
        return messageService.deleteMessage(params);
    }

    /**
    * <p>
    * 发布消息
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @ResponseBody
    @PostMapping("/insertMessage")
    public JsonResult insertMessage(@RequestBody Map<String,Object> params){
        return messageService.insertMessage(params);
    }

}
